﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using WP8.Binding.Classes;
using System.Text;
using System.Collections.ObjectModel;

namespace WP8.Binding.Pages
{
    public partial class CollectionBinding : PhoneApplicationPage
    {
        private ObservableCollection<Comida> comidas;

        public CollectionBinding()
        {
            InitializeComponent();
            Loaded += CollectionBinding_Loaded;
        }

        void CollectionBinding_Loaded(object sender, RoutedEventArgs e)
        {

        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            comidas = new ObservableCollection<Comida>();
            comidas.Add(new Comida() { Nombre = "Keke", Imagen = "/Assets/Imagenes/cake.png" });
            comidas.Add(new Comida() { Nombre = "Pan", Imagen = "/Assets/Imagenes/bread.png" });
            comidas.Add(new Comida() { Nombre = "Galleta", Imagen = "/Assets/Imagenes/cookie.png" });
            comidas.Add(new Comida() { Nombre = "Pizza", Imagen = "/Assets/Imagenes/pizza.png" });

            this.lbComidas.ItemsSource = comidas;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            List<Comida> comidas = this.lbComidas.ItemsSource as List<Comida>;

            StringBuilder sb = new StringBuilder();
            foreach (Comida item in comidas)
            {
                sb.AppendLine(item.Nombre + " - " + item.Observacion + " - " + item.Activo);
            }
            MessageBox.Show(sb.ToString());
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            foreach (var item in comidas)
            {
                item.Nombre = item.Nombre + " v2";
            }
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            comidas.Add(new Comida { Nombre = "Otro Keke", Imagen = "/Assets/Imagenes/cake.png" });
            comidas.Add(new Comida() { Nombre = "Cangreburger", Imagen = "/Assets/Imagenes/hamburger.png" });
        }

        //comidas.Add(new Comida() { Nombre = "Cangreburger", Imagen = "/Assets/Imagenes/hamburger.png" });
    }
}